from datetime import datetime

import nicegui
import mysql_orm

"""
安装：
pip install nicegui

配置
nicegui.ui.run(port=8080,title="芜湖",language="zh-CN")
"""
"""
with nicegui.ui.column():
    # 主体
    with nicegui.ui.card():
        nicegui.ui.label('金牛区日常管理系统')
        with nicegui.ui.column():
            # 账号和密码
            nicegui.ui.label('账号')
            zh = nicegui.ui.input(placeholder='请输入账号')
            nicegui.ui.label('密码')
            mm = nicegui.ui.input(placeholder='请输入密码',password=True,password_toggle_button=True)
            # todo 忘记密码
            # todo 登陆
            nicegui.ui.button('登陆')

nicegui.ui.run(port=8080,title="芜湖",language="zh-CN")
"""
# k = mysql_orm.sql_main(0)
# k.login_mode()
data_dict = {
    'Jinniu_Teacher_Info': [
        {'teacher_name': '张三', 'teacher_account': 'zhangsan', 'teacher_password': '123456', 'teacher_active': True, 'teacher_login_status': False, 'registration_time': datetime.now(), 'last_login_time': datetime.now(), 'remarks': '无'},
        {'teacher_name': '李四', 'teacher_account': 'lisi', 'teacher_password': '654321', 'teacher_active': True, 'teacher_login_status': False, 'registration_time': datetime.now(), 'last_login_time': datetime.now(), 'remarks': '无'}
    ],
    'Jinniu_School_Info': [
        {'province': '北京', 'urban_area': '北京市', 'district_and_county': '朝阳区', 'school_name': '北京小学', 'school_address': '北京市朝阳区', 'school_active': True, 'cooperation_period': '2022-01', 'person_teacher': '张三', 'remarks': '无'},
        {'province': '上海', 'urban_area': '上海市', 'district_and_county': '浦东新区', 'school_name': '上海中学', 'school_address': '上海市浦东新区', 'school_active': True, 'cooperation_period': '2022-01', 'person_teacher': '李四', 'remarks': '无'}
    ],
    'Jinniu_Student_Inf': [
        {'student_name': '王五', 'class_name': '一班', 'student_school': '北京小学', 'student_grade': '一年级', 'student_class': 1, 'student_type': '普教班', 'student_status': True, 'Instructor_teacher': '张三', 'remarks': '无'},
        {'student_name': '赵六', 'class_name': '一班', 'student_school': '上海中学', 'student_grade': '一年级', 'student_class': 1, 'student_type': '普教班', 'student_status': True, 'Instructor_teacher': '李四', 'remarks': '无'}
    ]
}
a1 = 'Jinniu_Teacher_Info'
a2 = [
    {'teacher_name': '张三', 'teacher_account': 'zhangsan', 'teacher_password': '123456', 'teacher_active': True,
     'teacher_login_status': False, 'registration_time': datetime.now(), 'last_login_time': datetime.now(),
     'remarks': '无'},
    {'teacher_name': '李四', 'teacher_account': 'lisi', 'teacher_password': '654321', 'teacher_active': True,
     'teacher_login_status': False, 'registration_time': datetime.now(), 'last_login_time': datetime.now(),
     'remarks': '无'}
]
# p = k.add_data2(a1,a2)
# print(p)
# k.commit_data()
# a=k.query_data('jinniu_teacher_info',select_columns=['teacher_name'])
# print(a)
# teacher_dicts = [dict(teacher.__dict__) for teacher in a]
# teacher_dicts = [{key: value for key, value in teacher.__dict__.items() if key != '_sa_instance_state'} for teacher in a]
# print(teacher_dicts)
mysql_orm.db.create_tables([mysql_orm.Jinniu_Teacher_Info,mysql_orm.Jinniu_School_Info,mysql_orm.Jinniu_Card_Info])
# 添加一条记录，不需要指定id
"""
teacher = mysql_orm.Jinniu_Teacher_Info.create(
    teacher_name='李四',
    teacher_account='lisi',
    teacher_password= '1234',
    # remarks= '无',
)

school = mysql_orm.Jinniu_School_Info.create(
    province='四川',
    urban_area='成都',
    district_and_county= '金牛',
    school_name='成都市沙湾路小学校',
    school_address='芜湖',
    cooperation_period = '2024年3月',
    person_teacher='张思'
    # remarks= '无',
)
"""
# 使用反向引用获取用户的所有帖子
# teacher_account ='zhangsan'
# # print(mysql_orm.Jinniu_Teacher_Info.get(teacher_account=teacher_account))
# schools = mysql_orm.Jinniu_School_Info.get_school_by_teacher_account(teacher_account)
# print(schools)
# for school in schools:
#     print(1)
#     print(school.school_name)
#     print(school)

# user_posts = mysql_orm.Jinniu_School_Info.school_name  # 这里的posts是反向引用属性
# print(user_posts)
# print(f"User {mysql_orm.Jinniu_School_Info.school_name} has {len(user_posts)} posts:")
# for post in user_posts:
#     print(f"- {post.title}")

a = {'teacher_name': '张三', 'teacher_account': 'zhangsan', 'teacher_password': 'wuhu',}
b = {'teacher_name': '李四', 'teacher_account': 'lisi', 'teacher_password': '123456',}

a2 = [
    {'teacher_name': '张三', 'teacher_account': 'zhangsan', 'teacher_password': '123456', 'teacher_active': True,
     'teacher_login_status': False, 'registration_time': datetime.now(), 'last_login_time': datetime.now(),
     'remarks': '无'},
    {'teacher_name': '李四', 'teacher_account': 'lisi', 'teacher_password': '654321', 'teacher_active': True,
     'teacher_login_status': False, 'registration_time': datetime.now(), 'last_login_time': datetime.now(),
     'remarks': '无'}
]
# todo 插入新值用法
# mysql_orm.Jinniu_Teacher_Info(**a).save()

# mysql_orm.Jinniu_Teacher_Info.create(**a)

# mysql_orm.Jinniu_Teacher_Info.insert(**a).execute()

# todo 批量插入用法
# mysql_orm.Jinniu_Teacher_Info.insert_many(a2).execute()

#k1 = mysql_orm.Jinniu_Teacher_Info(**a)
#k2 = mysql_orm.Jinniu_Teacher_Info(**b)
#mysql_orm.Jinniu_Teacher_Info.bulk_create([k1,k2])

# todo 更新用法
# mysql_orm.Jinniu_Teacher_Info(**a).update()
